<?php

include "../../../lib/start.php";

check_session();
check_permission(DOC_PERM);

//$f_f = fopen("../../tmp/dir.log", "w+");

$sel_classe = "SELECT classi.*, sedi.nome AS sede_des FROM classi, sedi WHERE classi.id_classe = ".$_REQUEST['cls']." AND classi.sede = sedi.id_sede";
$res_classe = $db->execute($sel_classe);
$current_class = new Classe($res_classe->fetch_assoc());
$_SESSION['__classe__'] = $current_class;

$today = date("Y-m-d");
$tomorrow = date("Y-m-d", strtotime($today." +1 days"));
if(date("w", $tomorrow) == 0)
	$tomorrow = date("Y-m-d", strtotime($today." +2 days"));

$sel_today_hw = "SELECT impegni.*, materie.materia AS mat FROM impegni, materie WHERE materie.id_materia = impegni.materia AND classe = ".$_SESSION['__classe__']->get_ID()." AND anno = ".$_SESSION['__current_year__']->get_ID()." AND data_inizio LIKE '$today%' AND impegni.tipo = 2 ORDER BY data_inizio DESC";
$res_today_hw = $db->execute($sel_today_hw);
$sel_today_act = "SELECT impegni.*, materie.materia AS mat FROM impegni, materie WHERE materie.id_materia = impegni.materia AND classe = ".$_SESSION['__classe__']->get_ID()." AND anno = ".$_SESSION['__current_year__']->get_ID()." AND data_fine LIKE '$today%' AND impegni.tipo = 1 ORDER BY data_inizio DESC";
$res_today_act = $db->execute($sel_today_act);

$sel_tomorrow_hw = "SELECT impegni.*, materie.materia AS mat FROM impegni, materie WHERE materie.id_materia = impegni.materia AND classe = ".$_SESSION['__classe__']->get_ID()." AND anno = ".$_SESSION['__current_year__']->get_ID()." AND data_inizio LIKE '$tomorrow%' AND impegni.tipo = 2 ORDER BY data_inizio DESC";
$res_tomorrow_hw = $db->execute($sel_tomorrow_hw);
$sel_tomorrow_act = "SELECT impegni.*, materie.materia AS mat FROM impegni, materie WHERE materie.id_materia = impegni.materia AND classe = ".$_SESSION['__classe__']->get_ID()." AND anno = ".$_SESSION['__current_year__']->get_ID()." AND data_fine LIKE '$tomorrow%' AND impegni.tipo = 1 ORDER BY data_inizio DESC";
$res_tomorrow_act = $db->execute($sel_tomorrow_act);

include "classe.html.php";

?>